<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
<script type="text/javascript" src="../src/Base.js"></script>
<script type="text/javascript" src="../src/Debug.js"></script>
<script type="text/javascript" src="../src/lib.js"></script>
<script type="text/javascript" src="../src/GownFullConfig.js"></script>
<script type="text/javascript" src="../src/GownFullBrowserDetect.js"></script>
<script type="text/javascript" src="../src/DataStructure.js"></script>
<script type="text/javascript" src="../src/GFWindow.js"></script>
<script type="text/javascript" src="../src/DebugWindow.js"></script>
<script type="text/javascript" src="../src/GownFullObjectAdapter.js"></script>
<script type="text/javascript" src="../src/JSVKBrowserExtension.js"></script>
<script type="text/javascript" src="../src/GownFullHTMLInputTextAdapter.js"></script>
<script type="text/javascript" src="../src/GownFullHTMLTextareaAdapter.js"></script>
<script>
var current_step = 0;
function step(i)
{
	var ta = document.getElementById('ta');
	var adapter = GownFullObjectAdapter.GetAdapter(ta);
	switch(i) {
	case 0:
		Debug.trace(0,'SetSelection(1,2)');
		adapter.SetSelection(1,2);
		break;
	case 1:
		Debug.trace(0,'DeleteSelection()');
		adapter.DeleteSelection();
		break;
	case 2:
		Debug.trace(0,'SendString(a)');
		adapter.SendString(null,'a');
		break;
	case 3:
		Debug.trace(0,'SetSelection(5,5)');
		adapter.SetSelection(5,5);
		break;
	case 4:
		Debug.trace(0,'SendString(ween)');
		adapter.SendString(null,'ween');
		Debug.trace(0,'End');
		break;
	default:
		return;
	}
	output(sprintf('Redo: %d, Undo: %d',adapter.redo_stack.count,adapter.undo_stack.count));
}
function main()
{
	var ta = document.getElementById('ta');
	var adapter;

	ta.value = 'Hello';
	ta.focus();
	adapter = new GownFullHTMLTextareaAdapter(ta);
	adapter.DisableUndo(true);
	ta.addEventListener('keypress', function(e) { 
		var key = e.which ? e.which : e.keyCode;

		if(key == 32) step(current_step++);
		else if(key == 39) redo();
		else if(key == 37) undo();
		e.preventDefault();
	},
	false);
}
function redo()
{
	var ta = document.getElementById('ta');
	var adapter = GownFullObjectAdapter.GetAdapter(ta);

	adapter.Redo();
	output(sprintf('Redo: %d, Undo: %d',adapter.redo_stack.count,adapter.undo_stack.count));
}
function undo()
{
	var ta = document.getElementById('ta');
	var adapter = GownFullObjectAdapter.GetAdapter(ta);

	adapter.Undo();
	output(sprintf('Redo: %d, Undo: %d',adapter.redo_stack.count,adapter.undo_stack.count));
}
</script>

<textarea id="ta" rows="10" cols="80"></textarea>
<p>Space to do the works<br />
Left Arrow to undo<br />
Right Arrow to redo</p>
<script type="text/javascript" src="test.js"></script>
<script>
Debug.verbose = 5;
Debug.start();
lib.LoadCSSFile('../gownfull.css');
main();
</script>
</body>
</html>
